<div id="basketlayout">
<div class="shoptop"><?php echo $this->translate( 'your_basket' ) ?></div>
<div class="box boxbasket">
	
	<div class="prodpage">
		<div class="acenter">
			<a href="javascript:void(null)" class="button prodmenu buttonactive"><?php echo $this->translate( 'basket_contents' ) ?></a>
			<a href="javascript:void(null)" class="button prodmenu"><?php echo $this->translate( 'basket_delivery' ) ?></a>
			<a href="javascript:void(null)" class="button prodmenu"><?php echo $this->translate( 'basket_payment' ) ?></a>
			<a href="javascript:void(null)" class="button prodmenu"><?php echo $this->translate( 'basket_confirmation' ) ?></a>
		</div>
	</div>
	
	<div id="ajaxreload">
	
    	<!-- start bar -->
    	<div class="basketbar">
    	
    		<div class="sekction sekpos1">
    			<p class="price"><?php echo $this->basket->sum ?></p>
    			<p class="name"><?php echo $this->translate( 'brutto_value' ) ?></p>
    		</div>
    		
    		<a href="{baseUrl}/shop/delivery" class="buttonred"><?php echo $this->translate( 'checkout' ); ?></a>
    	</div>
    	<!-- end bar -->
    	
    	<div class="options">
    	
			<?php
			$backTo = $this->baseUrl() . '/shop';
			?>
    		<a href="<?php echo $backTo; ?>" class="button"><?php echo $this->translate( 'back_to_shop' ); ?></a>
    		<a href="{baseUrl}/shop/wishlist/multi/1" class="button button2"><?php echo $this->translate( 'save_in_observed' ); ?></a>
    		<div class="clr"></div>
    	</div>
    	<!-- end options -->
    	
    	<h2><?php echo $this->translate( 'shop_basket_zaw' ) ?></h2>
    	<form method="post" action="<?php echo $this->baseUrl() ?>/shop/basket/save/">
		
		<?php 
		foreach( $this->basket->sess->basket['items'] as $value ) { 
			foreach( $value as $elem ) {
		?>
		<?php if( $elem['special'] ) { ?>
    	<div class="boxprod">
    		<div class="photo"><img src="<?php echo $this->File( $elem['info']['img'], 100 ) ?>" /></div>
    		<p class="name"><a href="{baseUrl}/shop/item/id/<?php echo $elem['info']['ps_id'] ?>/special/1/<?php echo $this->Seo( $elem['info']['name_' . $this->locale] ); ?>"><?php echo $elem['info']['name_' . $this->locale] ?></a></p>
    		<p class="price"><?php echo $this->PriceSpecial( $elem['info'], $this->priceRank, $this->locale, true ) ?></p>
            <table class="prodoption">
            	<tr>
            		<td><?php echo $this->translate( 'count' ) ?>:</td>
            		<td class="aleft">
            		<?php $linkInput = '{baseUrl}/shop/basket/sid/'.$elem['info']['ps_id'].'/free/'.$elem['free'].'/setamount/'; ?>
            			<select onchange="ajaxincrement('<?php echo $linkInput ?>'+$(this).val(),<?php echo $elem['info']['ps_id'] ?>)" id="ip_<?php echo $elem['info']['ps_id']  ?>_<?php echo $elem['dem'] ?>">
        						<?php 
        						 	
        						 for ($i=1; $i<=$elem['free'] ; $i++){
        						 	?>
        						 	<option value="<?php echo $i?>" <?php echo ($i==$elem['cnt'])? 'seleted="seleted"': '';?>><?php echo $i?></option>
        						 	<?php 
        						 }
            					 ?>
            			</select>
            		</td>
            	</tr>
            </table>
            <div id="ajax<?php echo $elem['info']['ps_id']?>" style="position:absolute; right:90px; top:15px; display:none"><img src="{baseUrl}/public/images/ajax1.gif" alt=""></div>
    		<a href="{baseUrl}/shop/basket/delete/<?php echo $elem['info']['ps_id'] ?>/dem/<?php echo $elem['dem'] ?>" class="button bold"><?php echo $this->translate( 'delete_from_basket' ) ?></a>
    	</div>
			<?php } else { ?>
    	<div class="boxprod">
    		<div class="photo" style="background-image:url(<?php echo $this->File(  $elem['info']['Galeries']['Photos']->toArray(), 117 ) ?>)"></div>
    		<p class="name"><a href="{baseUrl}/shop/item/id/<?php echo $elem['info']['p_id'] ?>/<?php echo $this->Seo( $elem['info']['name_' . $this->locale] ); ?>"><?php echo $elem['info']['name_' . $this->locale] ?></a></p>
    		<p class="price"><?php echo $this->Price( $elem['info'], $elem['free'], $this->locale, true ) ?></p>
            <table class="prodoption" border=0>
            	<tr>
            	
            		<td><?php echo $this->translate( 'capacity' ); ?>:</td>
            		<?php 
					 $linkSelect = $this->baseUrl().'/shop/basket/add/'.$elem['info']['p_id'].'/dem/'.$elem['dem'].'/newdem/';
					 ?>
            		<td class="aleft">
            			<div style="position:relative; top:2px">
            			<select class="stylish" onchange="ajaxincrement('<?php echo $linkSelect ?>'+$(this).val(),<?php echo $elem['info']['p_id'] ?>)"  id="dimension_<?php echo $elem['info']['p_id']; ?>_<?php echo $elem['dem']; ?>" name="dimension_<?php echo $elem['info']['p_id']; ?>_<?php echo $elem['dem']; ?>">
            			<?php 
							$i = 0; 
							foreach( $elem['info']['Dimension'] as $dim ) { 
								if( $dim['stock'] > 0 ) {
							?>
									<option <?php echo ( $i == $elem['free'] ) ? 'selected="selected"' : ''; ?> value="<?php echo $dim['d_id']; ?>"><?php echo $dim['name'] ?></option>
								<?php
								} 
								$i++;
							}
							?>	
            			</select>
            			</div>
            		</td>
            		<td><?php echo $this->translate( 'count' ) ?>:</td>
            		<td class="aright">
            			<?php $linkInput = $this->baseUrl().'/shop/basket/sid/'.$elem['info']['p_id'].'/free/'.$elem['free'].'/setamount/'; ?>


        						<?php if( $elem['cnt'] > 1 ) { ?>
        						
        						 <?php 
        						 $linkLeft = $this->baseUrl().'/shop/basket/add/'.$elem['info']['p_id'].'/minus/1/free/'.$elem['free'].'';
        						 ?>
        							 
        						<img onclick="ajaxincrement('<?php echo $linkLeft ?>',<?php echo $elem['info']['p_id'] ?>)" src="<?php echo $this->baseUrl(); ?>/public/images/stleft.jpg" class="st sh" alt="" style="position:relative; top:2px">
        						<?php } else { ?>
        						    <?php echo $this->inlineScript()->setScript( '$(document).ready(function(){
        								$( "#st_' . $elem['info']['p_id'] . '_' . $elem['dem'] . '" ).css({opacity:0.2, cursor: "default"});
        						})' ) ?>
        							
        						<img src="<?php echo $this->baseUrl(); ?>/public/images/stleft.jpg" id="st_<?php echo $elem['info']['p_id'] ?>_<?php echo $elem['dem'] ?>" class="st sh" alt="" style="position:relative; top:2px">
        						<?php } ?>
        						
        						<input type="hidden" id="ip_<?php echo $elem['info']['p_id']  ?>_<?php echo $elem['dem'] ?>_old" value="<?php echo $elem['cnt'] ?>" />
        						
            					 <?php 
            					 $linkInput = $this->baseUrl().'/shop/basket/sid/'.$elem['info']['p_id'].'/free/'.$elem['free'].'/setamount/';
            					 ?>
            			
            			</td>
            					 
        				<td class="acenter">	
        						
        						<input onblur="ajaxincrement('<?php echo $linkInput ?>'+$(this).val(),<?php echo $elem['info']['p_id'] ?>)"   id="ip_<?php echo $elem['info']['p_id']  ?>_<?php echo $elem['dem'] ?>" type="text" name="" class="acenter style1 icount" style="width:20px;" value="<?php echo $elem['cnt'] ?>"> 
						</td>
						
						<td class="aleft">
        						<?php if( $elem['cnt'] >= $elem['info']['Dimension'][$elem['free']]['stock'] ) { ?>
        							<?php echo $this->inlineScript()->setScript( '$(document).ready(function(){
        								$( "#stfor_' . $elem['info']['p_id'] . '_' . $elem['dem'] . '" ).css({opacity:0.2, cursor: "default"});
        						})' ) ?>
        						
        						<img src="<?php echo $this->baseUrl(); ?>/public/images/stright.jpg" id="stfor_<?php echo $elem['info']['p_id'] ?>_<?php echo $elem['dem'] ?>" class="st sh" alt="" style="position:relative; top:2px">
        						<?php } else { ?>
        
        						<?php 
        						$linkRight = $this->baseUrl().'/shop/basket/add/'.$elem['info']['p_id'].'/plus/1/free/'.$elem['free'].'';
        						?>
        						<img onclick="ajaxincrement('<?php echo $linkRight ?>',<?php echo $elem['info']['p_id'] ?>)" src="<?php echo $this->baseUrl(); ?>/public/images/stright.jpg" class="st sh" alt="" style="position:relative; top:2px">
        						<?php } ?>

						</td>

            		
            	</tr>
            </table>
            <div id="ajax<?php echo $elem['info']['p_id']?>" style="position:absolute; right:90px; top:15px; display:none"><img src="{baseUrl}/public/images/ajax1.gif" alt=""></div>
    		<a href="{baseUrl}/shop/basket/delete/<?php echo $elem['info']['p_id'] ?>/dem/<?php echo $elem['dem'] ?>" class="button bold"><?php echo $this->translate( 'delete_from_basket' ) ?></a>
    	</div>
    	<?php }?>
    	<?php }?>
    	</form>
    	<?php }?>
    	
	<?php if(isSet($this->basket->sess->basket['discount']) AND $this->basket->sess->basket['discount']!=0) {?>
	<h2><?php echo $this->translate( 'basket_kod_rab_przy' ); ?></h2>
	<p><?php echo $this->basket->sess->basket['discount']?>%</p>
		
	<?php } else { ?>
	<h2><?php echo $this->translate( 'basket_kod_rab2' ); ?></h2>
    	<form id="formajaxcode" class="acenter" method="post" action="<?php echo $this->baseUrl(); ?>/shop/basket" >
    	<table class="discountcode" style="margin:0 auto">
    		<tr>
    			<td><?php echo $this->translate( 'basket_kod_rab' ); ?>:</td>
    			<td><input type="text" name="code"></td>
    			<td><a href="javascript:;" class="button" onclick="$('#formajaxcode').submit()"><?php echo $this->translate( 'save_code' ) ?></a></td>
    		</tr>
    	</table>
    	</form>
	<?php } ?>
	
	</div>
	
	<div class="end"></div>
	<div style="height:1px; width:100%; margin:10px auto; background:#3d3d43"></div>
	
	<?php if($this->vouchers && $this->vouchers->getFirst()) { ?>
		<div style="position:relative">
		<form id="formajaxvouchers" method="post" action="<?php echo $this->baseUrl(); ?>/shop/basket"> 
		<table class="stoproc" style="margin-top:58px">
		<tr>
		<td style="vertical-align:top"><?php echo $this->translate( 'basket_my_voucher' ) ?>:</td>
		<td>
		
			<div class="scrollbarbox">
				<div class="rightbox">
    				<div id="scroll-top1" class="scroll-top"></div>
    				<div id="scroll-down1" class="scroll-down"></div>
    				<div id="scrolling1"></div>
				</div>
    			<div id="scrollbar1" class="scrollbar">
    			<ul id="scrolllist">
    			<?php foreach($this->vouchers as $one) { ?>
    				<li><p><input type="checkbox" <?php echo (isset($this->check_vol[$one->v_id])) ? 'checked="cheked"' : '';?>name="vouchers[<?php echo $one->v_id;?>]" value="<?php echo $one->value;?>" id="c<?php echo $one->v_id;?>"><label for="c<?php echo $one->v_id;?>">CARNAUBA <?php echo $one->value;?></label> </p></li>
    			<?php }?>
    			</ul>
    			</div>
			</div>

		</td>
		<td style="vertical-align:bottom; text-align:right">
		<?php echo $this->translate( 'basket_use_vouchers' ) ?>&nbsp;&nbsp;&nbsp;
		<input type="submit" class="button3" style="*position:relative; *bottom:-7px" value="<?php echo $this->translate( 'basket_conver_volchers' ) ?>">
		</td>
		</tr>
		</table>	
		<div id="ajaxvouchers" style="position:absolute; right:35px; top:10px; display:none"><img src="<?php echo $this->baseUrl(); ?>/public/images/ajax2.gif" alt=""></div>
		<input type="hidden" name="voucher" value="yes" />
		<input type="hidden" name="isajax" value="yes" />
		</form>
		</div>
	<?php }?>

</div>
</div>

<!-- end box -->

<script type="text/javascript">
	
		function ajaxincrement(url, idpr)
		{
			//Troche rusko ze to w callback jest ale inaczej 
			//przy async:false nie pojawia sie kreciol
			//a async:false musi byc.. bo jakby bylo async:true to przy szybkim klikaniu
			//w strzalki moze sie cala strona wysypac
			

			$('#ajax'+idpr).show(200, function(){

				$.ajax({
					  url: url,
					  cache:false,
					  async:false,
					  type: "POST",
					  data: ({isajax: "yes"}),
					  beforeSend: function(){
						//$('#ajax'+idpr).show();
				   	  },			  
					  success: function(data) {
      					$('#basketlayout').html(data);
      					$('#ajax'+idpr).hide();
      					stylishFormsCarnauba();
      					
					  }
					});

				});
			
		}

		/*
		function ajaxamount(url)
		{
			$('#ajax'+idpr).show(200, function(){

				$.ajax({
					  url: url,
					  cache:false,
					  async:false,
					  type: "POST",
					  data: ({isajax: "yes"}),
					  beforeSend: function(){
						//$('#ajax'+idpr).show();
				   	  },			  
					  success: function(data) {
      					$('#basketlayout').html(data);
      					$('#ajax'+idpr).hide();
      					stylishFormsCarnauba();
      					
					  }
					});

				});
		}
		*/
		
		$(document).ready(function(){
			
			var options1 = { 
					type: 'POST',
					target: '#basketlayout',
					replaceTarget: true,
					beforeSubmit: function() {
								$('#ajaxvouchers').show();
							},
				    success: function() {
							    stylishFormsCarnauba();
							    $('#ajaxvouchers').hide();
						    } 
				}; 
			
			//$('#formajaxvouchers').ajaxForm(options1);

			var options2 = { 
					type: 'POST',
					target: '#basketlayout',
					replaceTarget: true,
					beforeSubmit: function() {
								$('#usecode').hide();
								$('#ajaxcode').show();
							},
				    success: function() {
							    stylishFormsCarnauba();
						    } 
				}; 
			
			//$('#formajaxcode').ajaxForm(options2);
			
		});
		
</script>